package com.cxy.controller;

import com.cxy.entity.IftsBizCustAudit;
import com.cxy.entity.IftsBizCustAuditExample;
import com.cxy.inter.ExchRzTransNoticeMapper;
import com.cxy.inter.IftsBizCustAuditMapper;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicInteger;

/*********************************************************
 * 文件名称：Daotest.java
 * 系统名称：cxycloud
 * 模块名称：com.cxy.controller
 * 功能说明：
 * 开发人员 @author：caoxy
 * 开发时间 @date：2023/8/31 11:25
 * 修改记录：程序版本  修改日期  修改人员  修改单号  修改说明
 *********************************************************/
@RestController()
@Configuration
public class Daotest implements ApplicationContextAware {
    @Autowired
    private ExchRzTransNoticeMapper exchRzTransNoticeMapper;
    @Autowired
    private IftsBizCustAuditMapper iftsBizCustAuditMapper;
    @GetMapping("dao")
    public Object test() throws IllegalAccessException {
        long start = System.currentTimeMillis();
        System.out.println(new Date());
        // return iftsBizCustAuditMapper.selectByExampleWithPageSuffix(new IftsBizCustAuditExample(), Arrays.asList("2022","2023"),new RowBounds(1,2));
        IftsBizCustAudit iftsBizCustAudit = new IftsBizCustAudit();
        Field[] declaredFields = IftsBizCustAudit.class.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            declaredField.setAccessible(true);
            if (declaredField.getType() == String.class) {
                declaredField.set(iftsBizCustAudit,"1");
            }
        }
        ArrayList<IftsBizCustAudit> iftsBizCustAudits = new ArrayList<>();
        for (int i = 0; i < 10000000; i++) {
            iftsBizCustAudits.add(iftsBizCustAudit);
        }
        System.out.println( "开始" + new Date());
        AtomicInteger atomicInteger = new AtomicInteger();
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
        for (int i = 0; i < iftsBizCustAudits.size(); i+=3000) {
            List<IftsBizCustAudit> iftsBizCustAudits1 = iftsBizCustAudits.subList(i,
                    i + 3000 >= iftsBizCustAudits.size() ? iftsBizCustAudits.size() : i + 3000);
            scheduledExecutorService.execute(()->{
                iftsBizCustAuditMapper.insertBatchSuffix(iftsBizCustAudits1,"2023");
                System.out.println(atomicInteger.getAndIncrement() + " 完成  " + new Date());
            });
        }


        return System.currentTimeMillis() - start;
    }
    ApplicationContext  applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext =  applicationContext;
    }
    @PostMapping("services")
    public Object services(@RequestBody String req){
        System.out.println(req);
        return req;
    }
}
